package com.mutouren.common.orm;

import org.apache.ibatis.session.SqlSession;

import com.mutouren.common.log.LogAlias;
import com.mutouren.common.log.LogManager;
import com.mutouren.common.log.Logger;

public class IbatisTrans  implements Transcation  {

	private static Logger errorLogger = LogManager.getLogger(LogAlias.SystemError.toString());
	
	private SqlSession session;
	
	public IbatisTrans(String cfgName) {
		session = IbatisConfig.getSession(cfgName);		
	}
	
	@Override
	public SqlSession getSession() {
		return session;
	}

	@Override
	public void begin() {
		//session.		
	}

	@Override
	public void commit() {
		session.commit();		
	}

	@Override
	public void rollback() {		
		try {	
			if(session != null)
				session.rollback();
		} catch(Throwable t) {
			errorLogger.error("IbatisTrans rollback() error", t);
		}
	}

	@Override
	public void close() {
		try {
			if(session != null)
				session.close();
		} catch(Exception e) {
			errorLogger.error("IbatisTrans close fail!", e);
		}			
	}

}
